﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace NamazVakti
{
    [Serializable]
    public class NamazVakitleri
    {
        public DateTime Date
        {
            get;
            set;
        }

        public Vakit Imsak = Vakit.Imsak;
        public Vakit Gunes = Vakit.Gunes;
        public Vakit Ogle = Vakit.Ogle;
        public Vakit Ikindi = Vakit.Ikinki;
        public Vakit Aksam = Vakit.Aksam;
        public Vakit Yatsi = Vakit.Yatsi;

        public Vakit GetCurrentVakit()
        {
            if (Date.Date < DateTime.Now.Date || Date.Date > DateTime.Now.Date)
                return Vakit.Belirsiz;

            if (Imsak <= DateTime.Now && DateTime.Now < Gunes)
                return Imsak;
            else if (Gunes <= DateTime.Now && DateTime.Now < Ogle)
                return Gunes;
            else if (Ogle <= DateTime.Now && DateTime.Now < Ikindi)
                return Ogle;
            else if (Ikindi <= DateTime.Now && DateTime.Now < Aksam)
                return Ikindi;
            else if (Aksam <= DateTime.Now && DateTime.Now < Yatsi)
                return Aksam;
            else if (Yatsi <= DateTime.Now && DateTime.Now < Imsak.DateTime.AddDays(1))
                return Yatsi;

            return Vakit.Belirsiz;
        }

        public int GetRemainingTime()
        {
            Vakit current = GetCurrentVakit();
            
            if (current == VakitEnumeration.Yatsi)
                return (23 - DateTime.Now.TimeOfDay.Hours) * 60 + (60 - DateTime.Now.TimeOfDay.Minutes);
            else if (current == VakitEnumeration.Aksam)
                return (int)(Yatsi.DateTime - DateTime.Now).TotalMinutes;
            else if (current == VakitEnumeration.Ikinki)
                return (int)(Aksam.DateTime - DateTime.Now).TotalMinutes;
            else if (current == VakitEnumeration.Ikinki)
                return (int)(Ikindi.DateTime - DateTime.Now).TotalMinutes;
            else if (current == VakitEnumeration.Ikinki)
                return (int)(Ogle.DateTime - DateTime.Now).TotalMinutes;
            else if (current == VakitEnumeration.Ikinki)
                return (int)(Gunes.DateTime - DateTime.Now).TotalMinutes;
            else if (current == VakitEnumeration.Ikinki)
                return (int)(Imsak.DateTime - DateTime.Now).TotalMinutes;
            else //if (current == VakitEnumeration.None)
                return -1;
        }
    }
}
